package com.ruoyi.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.mapper.RecoverStationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mapper.PartyclassMapper;
import com.ruoyi.domain.Partyclass;
import com.ruoyi.service.IPartyclassService;
import com.ruoyi.service.IVideoRecoverStationService;
import com.ruoyi.domain.VideoRecoverStation;

/**
 * partyclassService业务层处理
 * 
 * @author ya
 * @date 2025-07-11
 */
@Service
public class PartyclassServiceImpl extends ServiceImpl<PartyclassMapper, Partyclass> implements IPartyclassService
{
    @Autowired
    private PartyclassMapper partyclassMapper;
    
    @Autowired
    private IVideoRecoverStationService videoRecoverStationService;
    @Autowired
    private RecoverStationMapper recoverStationMapper;

    @Override
    public List<Partyclass> selectPartyclassByType(int type) {
        return partyclassMapper.selectPartyclassByType(type);
    }

    /**
     * 查询partyclass
     * 
     * @param id partyclass主键
     * @return partyclass
     */
    @Override
    public Partyclass selectPartyclassById(Long id)
    {
        return partyclassMapper.selectPartyclassById(id);
    }

    /**
     * 查询partyclass列表
     * 
     * @param partyclass partyclass
     * @return partyclass
     */
    @Override
    public List<Partyclass> selectPartyclassList(Partyclass partyclass)
    {
        return partyclassMapper.selectPartyclassList(partyclass);
    }

    /**
     * 新增partyclass
     * 
     * @param partyclass partyclass
     * @return 结果
     */
    @Override
    public int insertPartyclass(Partyclass partyclass)
    {
        return partyclassMapper.insertPartyclass(partyclass);
    }

    /**
     * 修改partyclass
     * 
     * @param partyclass partyclass
     * @return 结果
     */
    @Override
    public int updatePartyclass(Partyclass partyclass)
    {
        return partyclassMapper.updatePartyclass(partyclass);
    }

    /**
     * 批量删除partyclass
     * 
     * @param ids 需要删除的partyclass主键
     * @return 结果
     */
    @Override
    public int deletePartyclassByIds(Long[] ids)
    {
        // 先将要删除的数据插入到回收站
        for (Long id : ids) {
            Partyclass partyclass = partyclassMapper.selectPartyclassById(id);
            if (partyclass != null) {
                VideoRecoverStation recoverStation = new VideoRecoverStation();
                recoverStation.setValidDate(30);
                // 复制字段
                recoverStation.setName(partyclass.getName());
                recoverStation.setFile(partyclass.getFile());
                if (partyclass.getPubdate() != null) {
                    recoverStation.setPubdate(partyclass.getPubdate());
                }
                recoverStation.setAuthor(partyclass.getAuthor());
                recoverStation.setVideoOrigin(partyclass.getVideoOrigin());
                recoverStation.setType(partyclass.getType());
                recoverStation.setCoverImg(partyclass.getCoverImg());
                if (partyclass.getX() != null) {
                    recoverStation.setX(partyclass.getX().longValue());
                }
                if (partyclass.getY() != null) {
                    recoverStation.setY(partyclass.getY().longValue());
                }
                if (partyclass.getSortOrder() != null) {
                    recoverStation.setSortOrder(partyclass.getSortOrder());
                }
                recoverStation.setVideoId(partyclass.getId());

                System.out.println("视频数据:"+recoverStation);
                
                // 插入到回收站
                videoRecoverStationService.insertVideoRecoverStation(recoverStation);
            }
        }

        
        // 执行删除操作
        return partyclassMapper.deletePartyclassByIds(ids);
    }

    /**
     * 删除partyclass信息
     * 
     * @param id partyclass主键
     * @return 结果
     */
    @Override
    public int deletePartyclassById(Long id)
    {
        return partyclassMapper.deletePartyclassById(id);
    }
    
    /**
     * 获取指定类型的最大排序值
     * 
     * @param type 视频类型
     * @return 最大排序值
     */
    @Override
    public int selectMaxSortOrderByType(int type)
    {
        return partyclassMapper.selectMaxSortOrderByType(type);
    }
    
    /**
     * 将指定类型下排序值小于给定值的记录的排序值加1
     * 
     * @param type 视频类型
     * @param sortOrder 排序值阈值
     */
    @Override
    public void incrementSortOrderForTypeLessThan(int type, int sortOrder)
    {
        partyclassMapper.incrementSortOrderForTypeLessThan(type, sortOrder);
    }
    
    /**
     * 查找指定类型下排序值刚好小于给定值的记录
     * 
     * @param type 视频类型
     * @param sortOrder 排序值
     * @return 记录对象
     */
    @Override
    public Partyclass selectPreviousPartyclass(int type, int sortOrder)
    {
        return partyclassMapper.selectPreviousPartyclass(type, sortOrder);
    }
    
    /**
     * 查找指定类型下排序值刚好大于给定值的记录
     * 
     * @param type 视频类型
     * @param sortOrder 排序值
     * @return 记录对象
     */
    @Override
    public Partyclass selectNextPartyclass(int type, int sortOrder)
    {
        return partyclassMapper.selectNextPartyclass(type, sortOrder);
    }
}
